<template>
  <div>
    <el-card>
      <div slot="header" class="clearfix">
        <span v-if="web_username == 'admin'">
          调用用户：
          <el-select
            style="width: 150px"
            v-model="getReviewdata.username"
            placeholder="请选择用户名称"
            clearable
          >
            <el-option
              :label="item.value"
              :value="item.key"
              v-for="(item, index) in userNameSelect"
              :key="index"
            >
            </el-option>
          </el-select>
        </span>
        手机号码：
        <el-input
          style="width: 150px"
          clearable
          v-model="getReviewdata.mdn"
          placeholder="请输入手机号码"
        ></el-input>
        真实姓名：<el-input
          clearable
          style="width: 100px"
          v-model="getReviewdata.name"
          placeholder="姓名"
        ></el-input>
        状态code：<el-input
          clearable
          style="width: 90px"
          v-model="getReviewdata.code"
          placeholder="code"
        ></el-input>
        开始时间：
        <el-input
          clearable
          style="width: 150px"
          v-model="getReviewdata.time"
          placeholder="时间"
        ></el-input>

        &nbsp;
        <el-button type="primary" @click="queryreview()">查询</el-button>
      </div>
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column type="index" width="50"> </el-table-column>
        <el-table-column
          align="center"
          prop="createTime"
          label="创建日期"
          width="180"
        >
        </el-table-column>

        <el-table-column
          align="center"
          prop="username"
          label=" 调用账户"
          width="120"
        >
        </el-table-column>
        <el-table-column
          align="center"
          width="110"
          prop="apiKey"
          label="调用接口"
        >
        </el-table-column>
        <el-table-column align="center" label="真实姓名" width="80">
          <template slot-scope="scope">
            <span v-show="false">{{
              (obj = JSON.parse(scope.row.params))
            }}</span>
            <span>{{ obj.name }}</span>
          </template>
        </el-table-column>

        <el-table-column align="center" label="身份证号" width="180">
          <template slot-scope="scope">
            <span v-show="false">{{
              (obj = JSON.parse(scope.row.params))
            }}</span>
            <span>{{ obj.idNo }}</span>
          </template>
        </el-table-column>

        <el-table-column align="center" label="手机号码" width="110">
          <template slot-scope="scope">
            <span v-show="false">{{
              (obj = JSON.parse(scope.row.params))
            }}</span>
            <span>{{ obj.mdn }}</span>
          </template>
        </el-table-column>

        <el-table-column align="center" prop="result" width="800" label="信息">
        </el-table-column>

        <el-table-column align="center" fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button
              v-if="web_username == 'admin'"
              @click="fhClick(scope.row)"
              type="text"
              size="small"
              >复核</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="this.getReviewdata.currentPage"
        :page-sizes="[5, 10, 30, 50, 100]"
        :page-size="this.getReviewdata.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="this.getReviewdata.totalCount"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import { querySubmitApi, getUsername, addReview } from "../../../api/sys";
export default {
  async created() {
    this.web_username = this.$store.state.user.role;
    if (this.web_username != "admin") {
      this.getReviewdata.username = window.localStorage.getItem("username");
    }
    let name = await getUsername();
    this.userNameSelect = name.data;

    this.alllist();
  },
  data() {
    return {
      dialogVisible: false,
      dialogVisible1: false,
      userNameSelect: [],
      getReviewdata: {
        username: "",
        mdn: "",
        name: "",
        code: "",
        number: 0,
        time: "",
        totalCount: 0,
        currentPage: 1,
        pageSize: 10,
        pageNum: 1,
      },
      dialogdata: {
        apikey: "",
        name: "",
        code: "",
        mdn: "",
        time: "",
        code: "",
        message: "",
      },
      tableData: [],
      reviewdata: {
        id: "",
        status: "",
        message: "",
        reviewUser: "",
      },
    };
  },
  methods: {
    async alllist() {
      let data = {
        username: this.getReviewdata.username,
        mdn: "",
        name: "",
        code: "",
        number: 0,
        time: "",
        totalCount: 0,
        currentPage: 1,
        pageSize: this.getReviewdata.pageSize,
        pageNum: this.getReviewdata.pageNum,
      };
      let a = await querySubmitApi(data);
      console.log(a);
      this.tableData = a.data.pageList;
      this.getReviewdata.totalCount = a.data.totalCount;
      this.getReviewdata.pageSize = a.data.pageSize;
      this.getReviewdata.pageCode = a.data.pageCode;
    },
    // 查询
    async queryreview() {
      let { mdn, name, username, code, time } = this.getReviewdata;
      if (mdn) {
        if (mdn && name && code && time) {
          this.getReviewdata.number = 7;
          let names = this.getReviewdata.name.slice(0, 1);
          this.getReviewdata.name = names + "**";
          let a = await querySubmitApi(this.getReviewdata);
          this.tableData = a.data.pageList;
          this.getReviewdata.totalCount = a.data.totalCount;
          this.getReviewdata.pageSize = a.data.pageSize;
          this.getReviewdata.pageNum = a.data.pageCode;
        } else if (mdn && name && code) {
          this.getReviewdata.number = 4;
          console.log(this.getReviewdata.number);
          let names = this.getReviewdata.name.slice(0, 1);
          this.getReviewdata.name = names + "**";
          let mdns = this.getReviewdata.mdn.slice(0, 3);
          let mdnss = this.getReviewdata.mdn.slice(8, 11);
          let mdnsss = mdns + "*****" + mdnss + "";
          this.getReviewdata.mdn = mdnsss;
          let a = await querySubmitApi(this.getReviewdata);
          this.tableData = a.data.pageList;
          this.getReviewdata.totalCount = a.data.totalCount;
          this.getReviewdata.pageSize = a.data.pageSize;
          this.getReviewdata.pageNum = a.data.pageCode;
        } else if (mdn && name && time) {
          this.getReviewdata.number = 5;
          console.log(this.getReviewdata.number);
          let names = this.getReviewdata.name.slice(0, 1);
          this.getReviewdata.name = names + "**";
          let mdns = this.getReviewdata.mdn.slice(0, 3);
          let mdnss = this.getReviewdata.mdn.slice(8, 11);
          let mdnsss = mdns + "*****" + mdnss + "";
          this.getReviewdata.mdn = mdnsss;
          let a = await querySubmitApi(this.getReviewdata);
          this.tableData = a.data.pageList;
          this.getReviewdata.totalCount = a.data.totalCount;
          this.getReviewdata.pageSize = a.data.pageSize;
          this.getReviewdata.pageNum = a.data.pageCode;
        } else if (mdn && code && time) {
          this.getReviewdata.number = 6;
          console.log(this.getReviewdata.number);
          let mdns = this.getReviewdata.mdn.slice(0, 3);
          let mdnss = this.getReviewdata.mdn.slice(8, 11);
          let mdnsss = mdns + "*****" + mdnss + "";
          this.getReviewdata.mdn = mdnsss;
          let a = await querySubmitApi(this.getReviewdata);
          this.tableData = a.data.pageList;
          this.getReviewdata.totalCount = a.data.totalCount;
          this.getReviewdata.pageSize = a.data.pageSize;
          this.getReviewdata.pageNum = a.data.pageCode;
        } else if (mdn && code) {
          this.getReviewdata.number = 2;
          console.log(this.getReviewdata.number);
          let mdns = this.getReviewdata.mdn.slice(0, 3);
          let mdnss = this.getReviewdata.mdn.slice(8, 11);
          let mdnsss = mdns + "*****" + mdnss + "";
          this.getReviewdata.mdn = mdnsss;
          let a = await querySubmitApi(this.getReviewdata);
          this.tableData = a.data.pageList;
          this.getReviewdata.totalCount = a.data.totalCount;
          this.getReviewdata.pageSize = a.data.pageSize;
          this.getReviewdata.pageNum = a.data.pageCode;
        } else if (mdn && time) {
          this.getReviewdata.number = 3;
          console.log(this.getReviewdata.number);
          let mdns = this.getReviewdata.mdn.slice(0, 3);
          let mdnss = this.getReviewdata.mdn.slice(8, 11);
          let mdnsss = mdns + "*****" + mdnss + "";
          this.getReviewdata.mdn = mdnsss;
          let a = await querySubmitApi(this.getReviewdata);
          this.tableData = a.data.pageList;
          this.getReviewdata.totalCount = a.data.totalCount;
          this.getReviewdata.pageSize = a.data.pageSize;
          this.getReviewdata.pageNum = a.data.pageCode;
        } else if (mdn && name) {
          this.getReviewdata.number = 1;
          console.log(this.getReviewdata.number);
          let names = this.getReviewdata.name.slice(0, 1);
          this.getReviewdata.name = names + "**";
          let mdns = this.getReviewdata.mdn.slice(0, 3);
          let mdnss = this.getReviewdata.mdn.slice(8, 11);
          let mdnsss = mdns + "*****" + mdnss + "";
          this.getReviewdata.mdn = mdnsss;
          let a = await querySubmitApi(this.getReviewdata);
          this.tableData = a.data.pageList;
          this.getReviewdata.totalCount = a.data.totalCount;
          this.getReviewdata.pageSize = a.data.pageSize;
          this.getReviewdata.pageNum = a.data.pageCode;
        } else if (mdn) {
          this.getReviewdata.number = 8;
          console.log(this.getReviewdata.number);
          let mdns = this.getReviewdata.mdn.slice(0, 3);
          let mdnss = this.getReviewdata.mdn.slice(8, 11);
          let mdnsss = mdns + "*****" + mdnss + "";
          this.getReviewdata.mdn = mdnsss;
          let a = await querySubmitApi(this.getReviewdata);
          this.tableData = a.data.pageList;
          this.getReviewdata.totalCount = a.data.totalCount;
          this.getReviewdata.pageSize = a.data.pageSize;
          this.getReviewdata.pageNum = a.data.pageCode;
        }
      } else {
        this.alllist();
      }
    },

    // 点击复核
    async fhClick(row) {
      let data = {
        id: row.subId,
        username: row.username,
      };
      await addReview(data);
    },

    // 分页/*  */
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.getReviewdata.pageSize = val;
      this.queryreview();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.getReviewdata.pageNum = val;
      this.queryreview();
    },
  },
};
</script>
